package c.x.jy.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import c.x.jy.dao.entity.RechargeEntity;
import c.x.jy.service.service.RechargeService;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;



/**
 * 会员充值计划
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-26 13:59:59
 */
@RestController
@RequestMapping("business/recharge")
public class RechargeController extends AbstractController {
    @Autowired
    private RechargeService rechargeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:recharge:list")
    public R list(@RequestParam Map<String, Object> params){
     	if(getUser().getBusinessId()>0) {
    		params.put("businessId", getUser().getBusinessId());
    	}
        PageUtils page = rechargeService.queryPage(params);

        return R.put(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:recharge:info")
    public R info(@PathVariable("id") Long id){
		RechargeEntity recharge = rechargeService.getById(id);

        return R.put(recharge);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:recharge:save")
    public R save(@RequestBody RechargeEntity recharge){
		rechargeService.save(recharge);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:recharge:update")
    public R update(@RequestBody RechargeEntity recharge){
		rechargeService.updateById(recharge);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("business:recharge:delete")
    public R delete(@PathVariable("id") Long id){
		rechargeService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

